<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/rp/common/taglib.jsp" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <base href="<%=basePath%>">
    
    <title>${ webpageTitle }</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
	
	<script src="rp/scripts/boot.js" type="text/javascript"></script>
	
	<style type="text/css">
	   	
    </style>
	
  </head>
  
  <body class="body-fit">
  	
  	<div style="width:100%;">
        <div class="mini-toolbar" style="border:0;padding:0px;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" onclick="showTaskForm()"><i class="fa fa-plus fa-lg"></i> 新增</a>
                        <a class="mini-button" onclick="changeTask('pause');"><i class="fa fa-pause fa-lg"></i> 暂停任务</a>
                        <a class="mini-button" onclick="changeTask('recover');"><i class="fa fa-play fa-lg"></i>  恢复任务</a>
                        <a class="mini-button mini-button-danger" onclick="changeTask('delete')"><i class="fa fa-trash-o fa-lg"></i> 删除任务</a>
                    </td>
                    <td style="white-space:nowrap;">
                    	
                    </td>
                </tr>
            </table>           
        </div>
    </div>
    
    <div class="mini-fit">
	  	<div id="taskGrid" class="mini-datagrid" 
	  		style="width: 100%; height: 100%;" borderStyle="border:0;"
	    	url="rp/system/taskMng/getTasks" idField="id" pageSize="20"
	    	allowResize="false"
	    	allowCellEdit="true" allowCellSelect="true" multiSelect="true" 
	        editNextOnEnterKey="true" editNextRowCell="true" allowCellValid="true">
		    <div property="columns">
		        <div type="indexcolumn" headerAlign="center">序号</div>
		        <div type="checkcolumn"></div>
		        <div name="" field="taskName" width="180" width="" headerAlign="center">
		        	任务名称
		        </div>    
		        <div name="" field="jobClass" width="150" width="" headerAlign="center">
		        	任务类全路径类名
		        </div>
		        <div name="" field="taskStatus" width="45" headerAlign="center" renderer="onTaskStatusRenderer">
		        	任务状态
		        </div>
		        <div name="" field="startTime" width="100" headerAlign="center" renderer="onDateRenderer">
		        	开始时间
		        </div>
		        <div name="" field="endTime" width="100" headerAlign="center" renderer="onDateRenderer">
		        	结束时间
		        </div>
		        <div name="" field="intervalTime" width="70" headerAlign="center">
		        	间隔时间/ms
		        </div>
		        <div field="createDate" width="100" headerAlign="center" allowSort="true" renderer="onDateRenderer2">
		        	创建日期
		        </div>                
		    </div>
		</div> 
  	</div>
  	
	<script type="text/javascript">
		var grid;
		
		$(function(){
			mini.parse();
			grid = mini.get("taskGrid");
			grid.load();
		});
		
		function onTaskStatusRenderer(e){
			var value = e.value;
			if(value == "运行中"){
				return "<span style='color:green;'>"+value+"</span>";
			}else if(value == "暂停"){
				return "<span style='color:red;'>"+value+"</span>";
			}else if(value == "已完成"){
				return "<span style='color:black;'>"+value+"</span>";
			}
		}
		
		function showTaskForm(){
			mini.open({
                url: "rp/system/taskMng/taskForm.jsp",
                title: "任务编辑", 
                width: 1024, 
                height: 400,
                showMaxButton: true,
                onload: function () {
                	
                },
                ondestroy: function (action) {
					grid.reload();
                }
            });
		}
		
		function changeTask(_operate){
			var s = "";
			if(_operate == "pause"){s="暂停"}
			else if(_operate == "recover"){s="恢复"}
			else if(_operate == "delete"){s="删除"}
			mini.confirm("确定"+s+"选中的任务吗？", "友情提示",
   	            function (action) {
   	                if (action == "ok") {
   	                	var rows = grid.getSelecteds();
	   	                 var json = mini.encode(rows);
	   	                 if (rows.length > 0) {
	   	                	if(_operate == "pause"){
	   	                		rp_ajax("rp/system/taskMng/changeTask", {json: json, operate: "pause"}, function(text){
		   	                 		grid.reload();
		   	                    });
	   	                	}if(_operate == "recover"){
	   	                		rp_ajax("rp/system/taskMng/changeTask", {json: json, operate: "recover"}, function(text){
		   	                 		grid.reload();
		   	                    });
	   	                	}if(_operate == "delete"){
	   	                		rp_ajax("rp/system/taskMng/changeTask", {json: json, operate: "delete"}, function(text){
		   	                 		grid.reload();
		   	                    });
	   	                	}
	   	                 }else{
	   	                	 mini.alert("您未选中任何记录");
	   	                 }
   	                }
   	            }
   	        );
		}
		
	</script>
  </body>
</html>
